package com.sumfun.blog.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sumfun.blog.mapper.CategoryMapper;
import com.sumfun.blog.model.domain.Category;
import com.sumfun.blog.service.CategoryService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* @author 17337
* @description 针对表【category(分类 )】的数据库操作Service实现
* @createDate 2024-05-05 10:40:21
*/
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Override
    public List<String> getCategoryNamesByIdList(List<Long> categoryIdList) {
        if(categoryIdList == null) {
            return new ArrayList<>();
        }
        return categoryIdList.stream()
                .map(categoryId -> Optional.ofNullable(this.getById(categoryId))
                        .map(Category::getCategoryName)
                        .orElse("Unknown"))  // 或者其他默认值
                .collect(Collectors.toList());
    }
}




